home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / CIREL.ZIP / EFFECT.CPP < prev    next >
C/C++ Source or Header  |  1995-05-11  |  2KB  |  106 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4. #pragma inline //Allows to use  386 code
  5. void hor(int x,int y,int x1,char col) // Draws one horizontal line
  6. {
  7.     int temp;
  8.     if(x>x1){
  9.     temp=x;
  10.     x=x1;
  11.     x1=temp;
  12.     }
  13.     asm{
  14.     mov ax,0a000h
  15.     mov es,ax
  16.     mov ax,320
  17.     mov bx,y
  18.     mul bx
  19.     add ax,x
  20.     mov di,ax
  21.     mov cx,x1
  22.     sub cx,x
  23.     mov al,col
  24.     rep stosb
  25.     }
  26. }
  27.  
  28.  
  29. void Circle(int x,int y,int r,int col)
  30. {
  31.     int i,xx,lx=r;
  32.     for(i=0;i<r+1;i++){   //Repeats only one quarter
  33.     xx=sqrt((r*r)-(i*i)); //This is the circle engine (not the fastest one but it works)
  34.                   //Look more info from ceh.doc
  35.     hor(x+xx,y+i,lx+x+1,col);
  36.     hor(x+xx,y-i,lx+x+1,col);
  37.     hor(x-xx,y+i,-lx+x-1,col);
  38.     hor(x-xx,y-i,-lx+x-1,col);
  39.     lx=xx;
  40.     }
  41. }
  42. void Ellipse(int x,int y,int a,int b,int col)
  43. {
  44.     int i,xx,lx=a;
  45.     for(i=0;i<b+1;i++){
  46.     xx=sqrt((double)(a*a)*((b*b)-(i*i)));
  47.     xx=xx/b;
  48.     hor(x+xx,y+i,lx+x+1,col);
  49.     hor(x+xx,y-i,lx+x+1,col);
  50.     hor(x-xx,y+i,-lx+x-1,col);
  51.     hor(x-xx,y-i,-lx+x-1,col);
  52.     lx=xx;
  53.     }
  54. }
  55. void Hyperbeli(int x,int y,int a,int b,int col)
  56. {
  57.     int i,xx,lx=a;
  58.     for(i=0;i<b+1;i++){
  59.     xx=sqrt((double)(a*a)*((b*b)+(i*i)));
  60.     xx=xx/b;
  61.     hor(x+xx,y+i,lx+x+3,col);
  62.     hor(x+xx,y-i,lx+x+3,col);
  63.     hor(x-xx,y+i,-lx+x-3,col);
  64.     hor(x-xx,y-i,-lx+x-3,col);
  65.     lx=xx;
  66.     }
  67. }
  68. void Clr()
  69. {
  70.     asm{
  71.     mov ax,0a000h
  72.     mov es,ax
  73.     xor ax,ax
  74.     xor di,di
  75.     mov cx,16000
  76.     rep stosd   //Clears 4 pixel per time
  77.     }
  78. }
  79. int main(void)
  80. {
  81.     int i;
  82.     asm mov ax,13h  // Puts 320*200*256 Mode on
  83.     asm int 10h
  84.     Circle(160,100,5,1);
  85.     getch();
  86.     for(i=0;i<90;i++){
  87.     Circle(160,100,i+5,i+1);
  88.     }
  89.     getch();Clr();
  90.     Ellipse(160,100,10,5,1);
  91.     getch();
  92.     for(i=0;i<40;i++){
  93.     Ellipse(160,100,i*2+10,i+5,i+1);
  94.     }
  95.     getch();Clr();
  96.     Hyperbeli(160,100,10,5,1);
  97.     getch();
  98.     for(i=0;i<40;i++){
  99.     Hyperbeli(160,100,i*2+10,i+5,i+1);
  100.     }
  101.     getch();
  102.  
  103.     asm mov ax,03 //Puts text mode back
  104.     asm int 10h
  105.     return 0;
  106. }